package com.wbl.tijiancms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wbl.tijiancms.mapper.CheckitemdetailedMapper;
import com.wbl.tijiancms.mapper.CidetailedreportMapper;
import com.wbl.tijiancms.pojo.Cidetailedreport;
import com.wbl.tijiancms.pojo.Cireport;
import com.wbl.tijiancms.pojo.Orders;
import com.wbl.tijiancms.response.ApiRestResponse;
import com.wbl.tijiancms.response.TijianExceptionEnum;
import com.wbl.tijiancms.service.CireportService;
import com.wbl.tijiancms.mapper.CireportMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @author yy
* @description 针对表【cireport】的数据库操作Service实现
* @createDate 2024-09-18 10:09:07
*/
@Service
public class CireportServiceImpl extends ServiceImpl<CireportMapper, Cireport>
    implements CireportService{

    @Autowired
    CireportMapper cireportMapper;

    @Autowired
    CidetailedreportMapper cidetailedreportMapper;

    @Autowired
    CheckitemdetailedMapper checkitemdetailedMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public ApiRestResponse createCireport(Orders order) throws Exception{
        List<Cireport> cireportList = cireportMapper.isexsit(order);
        List<Cidetailedreport> cidetailedreportList = cidetailedreportMapper.isexsit(order);
        if(!cireportList.isEmpty()||!cidetailedreportList.isEmpty()){
            return ApiRestResponse.success("历史已插入");
        }
        List<Cireport> cireports = cireportMapper.getCireport(order);
        int i = cireportMapper.insertList(cireports);
        List<Cidetailedreport> cidetailedreports = cidetailedreportMapper.select(order);
        int ii = cidetailedreportMapper.insertList(cidetailedreports);
        if (i>0&&ii>0){
            return ApiRestResponse.success("加载成功");
        }
        return ApiRestResponse.error(TijianExceptionEnum.SYSTEM_ERROR);
    }

    @Override
    public ApiRestResponse getReportList(Orders orders) {
        List<Cireport> cireports = cireportMapper.getReportList(orders);
        return ApiRestResponse.success(cireports);
    }

    @Override
    public ApiRestResponse editValue(List<Cidetailedreport> cidetailedreports) {
        for(Cidetailedreport cidetailedreport: cidetailedreports){
            int i = cidetailedreportMapper.editValue(cidetailedreport);
            if(i==0){
                return ApiRestResponse.error(TijianExceptionEnum.SYSTEM_ERROR);
            }
        }
            return ApiRestResponse.success("修改完成");
    }
}




